package chapter5;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description: 月历生成
 * Date:2021/4/3
 * ***************************************************************
 */
public class exc5_29 {
	public static void main(String[] args) {
		String[] months = {"January","February","March","April","May","Jun","July","August","September","October","November","December"};
		String[] days={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturay"};
		int[] numDays = {31,28,31,30,31,30,31,31,30,31,30,31};
		
		Scanner input=new Scanner(System.in);
		System.out.print("Enter the Year:  ");
		int year=input.nextInt();
		System.out.print("Enter the first day:  ");
		int first=input.nextInt();
		
		for(int i=1;i<=12;i++) {
			//计算本个月的首日期
			if(i>1) {
				first=(first+numDays[i-1])%7;
			}
			
			System.out.println("\t\t\t\t        "+months[i-1]+"  "+year);
			System.out.println("-----------------------------------------------------------------------");
			System.out.println("Sun\t\tMon\t\tTue\t\tWed\t\tThu\t\tFri\t\tSat");
			for(int j=0;j<first;j++) {
				System.out.print("   \t\t");
			}
			//使用base count两个变量调节每个月份的显示格式
			//保证每个月份每行7个日子
			int base=first;
			int count=first;
			for(int j=1;j<=numDays[i-1];j++) {
				System.out.printf("%2d\t\t",j);
				count++;
				if(count%7==0&&count!=base) {
					System.out.print("\n");
					base+=7;
				}
			}
			System.out.print("\n\n\n");
			
			
		}
		
		
	}

}
